package com.ruoyi.dzzh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dzzh.domain.DzzhDuty;
import com.ruoyi.dzzh.service.IDzzhDutyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 值班管理Controller
 * 
 * @author cjt
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/dzzh/duty")
public class DzzhDutyController extends BaseController
{
    @Autowired
    private IDzzhDutyService dzzhDutyService;

    /**
     * 查询值班管理列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:duty:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzzhDuty dzzhDuty)
    {
        startPage();
        List<DzzhDuty> list = dzzhDutyService.selectDzzhDutyList(dzzhDuty);
        return getDataTable(list);
    }

    /**
     * 导出值班管理列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:duty:export')")
    @Log(title = "值班管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzzhDuty dzzhDuty)
    {
        List<DzzhDuty> list = dzzhDutyService.selectDzzhDutyList(dzzhDuty);
        ExcelUtil<DzzhDuty> util = new ExcelUtil<DzzhDuty>(DzzhDuty.class);
        util.exportExcel(response, list, "值班管理数据");
    }

    /**
     * 获取值班管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dzzh:duty:query')")
    @GetMapping(value = "/{dutyId}")
    public AjaxResult getInfo(@PathVariable("dutyId") Long dutyId)
    {
        return AjaxResult.success(dzzhDutyService.selectDzzhDutyByDutyId(dutyId));
    }

    /**
     * 新增值班管理
     */
    @PreAuthorize("@ss.hasPermi('dzzh:duty:add')")
    @Log(title = "值班管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzzhDuty dzzhDuty)
    {
        return toAjax(dzzhDutyService.insertDzzhDuty(dzzhDuty));
    }

    /**
     * 修改值班管理
     */
    @PreAuthorize("@ss.hasPermi('dzzh:duty:edit')")
    @Log(title = "值班管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzzhDuty dzzhDuty)
    {
        return toAjax(dzzhDutyService.updateDzzhDuty(dzzhDuty));
    }

    /**
     * 删除值班管理
     */
    @PreAuthorize("@ss.hasPermi('dzzh:duty:remove')")
    @Log(title = "值班管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dutyIds}")
    public AjaxResult remove(@PathVariable Long[] dutyIds)
    {
        return toAjax(dzzhDutyService.deleteDzzhDutyByDutyIds(dutyIds));
    }
}
